﻿#include "pch.h"
#include "staticRouter.h"

WoHttpRouterPtr WEBOAT_API WoCreateRouter() {
	return oatpp::web::server::HttpRouter::createShared();
}
std::vector<const char*> g_Methods = {"GET","POST","HEAD","PUT","PATCH","DELETE","OPTIONS","CONNECT","TRACE"};
void WEBOAT_API WoRegisterRouter(WoHttpRouterPtr router, int Methods,const char*path, 
	WoRequestHandlerPtr hander,void* parame1) {
	if (Methods<0 || Methods>g_Methods.size()-1) {return;};
	auto eh = hander->GetEndHandler();
	g_logger->info("| [{:^9}] | {} | [0x{:x}](*{})->{}", g_Methods[Methods], path,
		eh.model == 0 ?
		(DWORD)eh.func :  //函数回调返回函数指针
		(DWORD)eh.routerHandle.get(), //空间回调返回空间地址
		eh.model == 0?"function":"class space",
		eh.model == 0 ?
		typeid(*hander->GetEndHandler().func).name():
		parame1==nullptr ? std::string(typeid(hander->GetEndHandler().routerHandle.get()).name())+" -> "+ g_Methods[Methods]:
		std::string(WoCodingUTF82GBK((char*)parame1)) + "::" + g_Methods[Methods]
	); 
	router->route(g_Methods[Methods], path, hander);
}

void WEBOAT_API WoRegisterStaticRouter(WoHttpRouterPtr router, const char* path, const char* localPath, void* parame1) {
	g_logger->info("| [{:^9}] | {} | [FileDir]->{}","StaticDir", path+std::string( + "/*"), localPath);
	router->route("GET", path+std::string("*"), std::make_shared<WoRequestStaticHandler>(path,localPath));
}
//void WEBOAT_API WoRegisterRouterApiController(WoHttpRouterPtr router, int Methods, const char* path,
//	WoRequestHandlerPtr hander) {
//	if (Methods<0 || Methods>g_Methods.size() - 1) { return; };
//	router->route(g_Methods[Methods], path, hander);
//}